<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            background-color: aqua;
            height: 100px;
        }
    </style>
</head>
<!-- v-on 常用修饰符 -->
<body>
    <div id="app">

        <!-- 1. 阻止事件冒泡 -->
        <h3>阻止事件冒泡 @click.stop </h3>
        <div class="box" @click="onBoxClick">            
            <button @click.stop="onButtonClick">阻止事件冒泡  @click.stop </button>
        </div>

        <!-- 2. 阻止默认事件 -->
        <br>
        <h3>阻止默认事件 @click.prevent</h3>
        <form action="www.baidu.com">
            <!-- 使用 @click.prevent 之后，当前界面就不会自动跳转 action 中的地址了 -->
            <input type="submit" value="提交" @click.prevent="doFormClick"/>
        </form>
        <a href="www.baidu.com" @click.prevent="doAClick" >百度一下</a>

        
        <!-- 3. 点击一次事件 -->
        <br>
        <h3>点击一次事件</h3>
        <button @click.once="onButtonClick">点击一次事件  @click.once </button>

        <!-- 4. 监听键盘事件 -->
        <br>
        <h3>监听键盘事件</h3>
        <input @keyup.enter="onEnter" placeholder="监听键盘 enter事件  @keyup.enter" />
    </div>
    <script src="js/vue.js"></script>

    <script>
        const HelloVue = {
            data(){
                return {
                    msg: "消息",
                }
            },
            methods: {
                onBoxClick(){
                    console.log("点击了盒子");
                },
                onButtonClick(){
                    console.log("点击了按钮");
                },
                doFormClick(){
                    console.log("表单提交");
                },
                doAClick(){
                    console.log("百度一下");
                },
                onEnter(event){
                    console.log(event.target.value);
                }
            }
        };

        const app = Vue.createApp(HelloVue).mount("#app");
       
    </script>
</body>
</html>